<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>渲染obj</title>
</head>
<body>
<script>

// ---- 震惊 =  =。
String.prototype.render = function (obj) {
  with(obj) {
    return eval('`' + this + '`')
  }
}

/* 靠谱解法

 String.prototype.render = function (obj) {
   eval(`var {${Object.keys(obj).join(',')}} = obj`)
   return eval('`' + this + '`')
 }

*/


// ---- 题目 ----
var greeting = 'My name is ${name}, age ${age}, I am a ${job.jobName}';
var emp = {
  name: 'Toma',
  age: 11,
  job: {
    jobName: 'designer',
    jobLevel: 'senior'
  }
}
var result = greeting.render(emp);
console.log(result);

</script>
</body>
</html>